home *** CD-ROM | disk | FTP | other *** search
- Path: news.us.net!usenet
- From: thoth256@us.net (Evelio Perez-Albuerne)
- Newsgroups: comp.lang.c++
- Subject: Re: Derived class not calling overloaded base class function
- Date: Fri, 23 Feb 1996 20:02:49 GMT
- Organization: US Net
- Message-ID: <4gl6d7$7jg@news.us.net>
- References: <4g46t2$3vd@otis.netspace.net.au> <fcusack-1902960717170001@mudskipper.cac.psu.edu>
- NNTP-Posting-Host: thoth256.laurel.us.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- In article <4g46t2$3vd@otis.netspace.net.au>, TorrBoy@netspace.net.au
- wrote:
-
- > Hi,
- >
- > Hopefully a very simple question someone can answer for me!
- >
- > I have a class, say 'foo' (everyone's favourite) which has a member function
- > 'int Get(void)'
- >
- > I then derive a class (say 'goo') which has as a base class foo. If goo has a
- > function also called Get, but with different params (say ''char* Get(char *)') I can't
- > seem to get the base class' Get() function to operate within the derived class.
- >
- > If I say just plain "Get()" it says too few parameters (for Get(char *)".
- > If I use
- > "::Get()" the compiler complains Get should have a prototype.
- > If I say "foo.Get()" it
- > says improper use of typedef foo.
-
- Although this behavior - a function in a derived class hides all
- functions in base classes with the same name *even* if they have
- different parameters - seems illogical it is correct as per the ARM.
- See Scott Meyer's "Effective C++" book for an explanation of why this
- was decided.
-
- To use the original int Get() function you need to redefine it in the
- derived class. Fortunately, the implementation is trivial (just call
- the base class function) and by using inlining, the compiler can
- optimize the additional function call away:
-
- class foo
- {
- // other stuff
- public:
- int Get();
- };
-
- class goo : public foo
- {
- // other stuff
- public:
- char* Get(char*);
- int Get() { return foo::Get(); }
- };
-
-
- ********************************************************
- Evelio Perez-Albuerne <thoth256@us.net>
-
-